package com.wcy.controller.resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.ResourceCategory;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.resource.FeignResourceCategoryService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class ResourceCategoryController {
    @Resource
    private FeignResourceCategoryService feignResourceCategoryService;
    @GetMapping("category/page")
    public ResponseEntity<PageData<ResourceCategory>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                              @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(ResourceCategory.class, Objects.requireNonNull(feignResourceCategoryService.getPage(pageNum, pageSize).getBody()),new ApiDescriptor("category/add","category/update","category/delete"), ColumnConstructor.create()));
    }

    @GetMapping("category/list")
    public ResponseEntity<List<ResourceCategory>> getList() {
        return feignResourceCategoryService.getList();
    }

    @PostMapping("category/add")
    public ResponseEntity<Void> add(@RequestBody ResourceCategory resourceCategory) {
        return feignResourceCategoryService.add(resourceCategory);
    }

    @PutMapping("category/update")
    public ResponseEntity<Void> update(@RequestBody ResourceCategory resourceCategory) {
        return feignResourceCategoryService.update(resourceCategory);
    }
    @DeleteMapping("category/delete")
    public ResponseEntity<Void> delete(Integer id) {
        return feignResourceCategoryService.delete(id);
    }
    @GetMapping("category/get/{id}")
    public ResponseEntity<ResourceCategory> get(@PathVariable("id") Integer id) {
        return feignResourceCategoryService.get(id);
    }
}
